﻿using System.Collections.Generic;
using System.ComponentModel;
using LiveTiss.Classes;

namespace LiveTiss.Schemas
{
    [System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://www.ans.gov.br/padroes/tiss/schemas")]
    public partial class ct_endereco : IDataErrorInfo
    {
        #region Public Properties - Custom

        [System.Xml.Serialization.XmlIgnoreAttribute()]
        public List<KeyValuePair<string, string>> tipoLogradouroItems
        {
            get
            {
                return XML_enum.TipoLogradouro;
            }
        }

        [System.Xml.Serialization.XmlIgnoreAttribute()]
        public List<KeyValuePair<string, string>> ufItems
        {
            get
            {
                return XML_enum.UF;
            }
        }

        #endregion

        #region IDataErrorInfo

        private bool IsRequired
        {
            get
            {
                return (!string.IsNullOrEmpty(this.logradouroField) || !string.IsNullOrEmpty(this.numeroField) || !string.IsNullOrEmpty(this.complementoField)
                    || !string.IsNullOrEmpty(this.codigoIBGEMunicipioField) || !string.IsNullOrEmpty(this.municipioField) || !string.IsNullOrEmpty(this.cepField));
            }
        }

        private string _error = null;

        [System.Xml.Serialization.XmlIgnoreAttribute()]
        public string Error
        {
            get
            {
                return _error;
            }
        }

        [System.Xml.Serialization.XmlIgnoreAttribute()]
        public string this[string propertyName]
        {
            get
            {
                _error = null;
                switch (propertyName)
                {
                    case "logradouro":
                        if (string.IsNullOrEmpty(this.logradouroField))
                        {
                            _error = "Campo Obrigatório";
                        }
                        break;
                    case "numero":
                        if (string.IsNullOrEmpty(this.numeroField))
                        {
                            _error = "Campo Obrigatório";
                        }
                        break;
                    case "codigoIBGEMunicipio":
                        if (string.IsNullOrEmpty(this.codigoIBGEMunicipioField))
                        {
                            _error = "Campo Obrigatório";
                        }
                        break;
                    case "cep":
                        if (string.IsNullOrEmpty(this.cepField))
                        {
                            _error = "Campo Obrigatório";
                        }
                        break;
                }
                return _error;
            }
        }

        #endregion
    }
}
